package com.yzd.learnjava.enumerated;

import java.util.Random;

import com.yzd.learnjava.util.Print;

public class RoShamBo1 {
	static final int SIZE = 20;
	private static Random random = new Random(47);
	public static Item newItem() {
		switch (random.nextInt(3)) {
		default:
		case 0:
			return new Scissors();
		case 1:
			return new Paper();
		case 2:
			return new Rock();
		}
	}
	
	public static void match(Item a , Item b) {
		Print.print(a + " vs. " + b + ": " + a.compete(b));
	}
	
	public static void main(String[] args) {
		for(int i = 0; i < SIZE; i++) {
			match(newItem(), newItem());
		}
	}
}

interface Item{
	Outcome compete(Item it);
	Outcome eval(Paper p);
	Outcome eval(Scissors s);
	Outcome eval(Rock r);
	
}

class Paper implements Item{

	public Outcome compete(Item it) {return it.eval(this);}
	public Outcome eval(Paper p) {return Outcome.DRAW;}
	public Outcome eval(Scissors s) {return Outcome.WIN;}
	public Outcome eval(Rock r) {return Outcome.LOSE;}
	public String toString() {return "Paper";}
	
}

class Scissors implements Item{
	public Outcome compete(Item it) {return it.eval(this);}
	public Outcome eval(Paper p) {return Outcome.LOSE;}
	public Outcome eval(Scissors s) {return Outcome.DRAW;}
	public Outcome eval(Rock r) {return Outcome.WIN;}
	public String toString() {return "Scissors";}
}

class Rock implements Item{
	public Outcome compete(Item it) {return it.eval(this);}
	public Outcome eval(Paper p) {return Outcome.WIN;}
	public Outcome eval(Scissors s) {return Outcome.LOSE;}
	public Outcome eval(Rock r) {return Outcome.DRAW;}
	public String toString() {return "Rock";}
}
